//
//  Player.m
//  Maze
//
//  Created by Lin Tian on 9/19/11.
//  Copyright 2011 tina. All rights reserved.
//

#import "Player.h"
#import "Room.h"

@implementation Player

@synthesize playerSprite = _playerSprite;
@synthesize speed = _speed;
@synthesize position = _position;
@synthesize playerId = _playerId;
@synthesize room = _room;
@synthesize forceId = _forceId;
@synthesize loadingProgress = _loadingProgress;
@synthesize itemList;

+(id) player{
    return [[[self alloc] initWithPlayerId:0 name:@" "] autorelease];
}

+(id) playerWithPlayerId:(unsigned int)playerId name:(NSString*)playerName
{
    return [[[self alloc] initWithPlayerId:playerId name:playerName] autorelease];
}

-(id) initWithPlayerId:(unsigned int)playerId name:(NSString*)playerName
{
    if ((self = [super init])) {
        self.playerId = playerId;
        self.loadingProgress = 0;
    }
    return self;
}

-(void)dealloc
{
    [self.playerSprite release];
    self.playerSprite = nil;
    
    [itemList release];
    itemList = nil;
    [super dealloc];
}

-(id) initSpriteWithParentNode:(CCNode*)parentNode position:(CGPoint)loc
{
	if ((self = [super init])) {
		_playerSprite = [CCSprite spriteWithFile:@"Player.png"];
		_playerSprite.position = loc;
		[parentNode addChild:_playerSprite];
		
        self.position = loc;
        self.speed = CGPointMake(0, 0);
    }
    return self;
}

-(void)setPosition:(CGPoint)position
{
    //send the position info to server
    
    //update the local position
    _position = position;
    _playerSprite.position = _position;
    
    /*CCSprite *footprint = [CCSprite spriteWithFile:@"footprint.gif"];
    footprint.position = _position;
    footprint.opacity = 100;
    [footprint runAction:[CCSequence actions:[CCFadeTo actionWithDuration:20 opacity: 0.0], [CCCallFuncN actionWithTarget:self selector:@selector(removeFootPrint:)], nil]];
    [self.playerSprite.parent addChild:footprint];*/
}

-(void)removeFootPrint:(CCNode*)node
{
    [node.parent removeChild:node cleanup:YES];
}

/*-(void)useItem:(int)itemId
{
    Item* anItem = nil;
    for (int i = 0; i < [self.itemList count]; i++) {
        anItem = (Item*)[self.itemList objectAtIndex:i];
        if(anItem.idNum == itemId)
        {
            [anItem useItem];
        }
    }
}*/

@end
